package com.example.javaairportflightanalysis.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.example.javaairportflightanalysis.common.ApiRestResponse;
import com.example.javaairportflightanalysis.domin.check.DfdlCheckAD;
import com.example.javaairportflightanalysis.domin.check.TransferCheckAD;
import com.example.javaairportflightanalysis.service.AuditService;
import com.example.javaairportflightanalysis.service.DfdlCheckService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 更改航班的接口，需要审核人审核
 */
@RestController
@RequestMapping("/dfdlcheck")
@CrossOrigin(origins = "*",maxAge = 3600)
//@SaCheckLogin
public class DfdlCheckController {
    @Resource
    DfdlCheckService dfdlCheckService;
    @Resource
    AuditService auditService;
    /**
     * A2航班的提交审核和查看审核
     */
    @PostMapping("/checkA2")
    @SaCheckRole("ROLE_MANAGEMENT")
    public ApiRestResponse checkA2(@RequestBody DfdlCheckAD dfdlCheckAD ){
        Integer id = dfdlCheckAD.getId();
        dfdlCheckService.updateDfdlCheckA(id, dfdlCheckAD);
        return ApiRestResponse.success();
    }
    @GetMapping("/getA2")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse getA2(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(dfdlCheckService.selectAllDfdlCheckA(pageNum, pageSize));
    }

    @GetMapping("/searchBy")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse searchBy(@RequestParam String dfltFlno, @RequestParam Integer status,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(auditService.searchBy(dfltFlno,status,pageNum, pageSize));
    }


    @GetMapping("/searchByTransferCheckA")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse searchByTransferCheckA(@RequestParam String dfltFlno, @RequestParam Integer status,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(auditService.searchByTransferCheckA(dfltFlno,status,pageNum, pageSize));
    }

    @GetMapping("/searchByDfdlCheckD")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse searchByDfdlCheckD(@RequestParam String dfltFlno, @RequestParam Integer status,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(auditService.searchByDfdlCheckD(dfltFlno,status,pageNum,pageSize));
    }

    @GetMapping("/searchByTransferD")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse searchByTransferD(@RequestParam String dfltFlno, @RequestParam Integer status,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(auditService.searchByTransferD(dfltFlno,status,pageNum,pageSize));
    }
    /**
     * A3航班的提交审核和查看审核
     */
    @PostMapping("/checkA3")
    @SaCheckRole("ROLE_MANAGEMENT")
    public ApiRestResponse checkA3(@RequestBody TransferCheckAD transferCheckAD ){
        Integer id = transferCheckAD.getId();
        dfdlCheckService.updateTransferCheckA(id, transferCheckAD);
        return ApiRestResponse.success();
    }
    @GetMapping("/getA3")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse getA3(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(dfdlCheckService.selectAllTransferCheckA(pageNum, pageSize));
    }

    /**
     * D2航班的提交审核和查看审核
     */
    @PostMapping("/checkD2")
    @SaCheckRole("ROLE_MANAGEMENT")
    public ApiRestResponse checkD2(@RequestBody DfdlCheckAD dfdlCheckAD ){
        Integer id = dfdlCheckAD.getId();
        dfdlCheckService.updateDfdlCheckD(id, dfdlCheckAD);
        return ApiRestResponse.success();
    }
    @GetMapping("/getD2")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse getD2(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(dfdlCheckService.selectAllDfdlCheckD(pageNum, pageSize));
    }

    /**
     * D3航班的提交审核和查看审核
     */
    @PostMapping("/checkD3")
    @SaCheckRole("ROLE_MANAGEMENT")
    public ApiRestResponse checkD3(@RequestBody TransferCheckAD transferCheckAD ){
        Integer id = transferCheckAD.getId();
        dfdlCheckService.updateTransferCheckD(id, transferCheckAD);
        return ApiRestResponse.success();
    }
    @GetMapping("/getD3")
    @SaCheckRole(value = {"ROLE_MANAGEMENT", "ROLE_AUDITOR"},mode = SaMode.OR)
    public ApiRestResponse getD3(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        return ApiRestResponse.success(dfdlCheckService.selectAllTransferCheckD(pageNum, pageSize));
    }

}
